Skip to content

Fix shipping discount failed to apply during place order #18096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

torreytsui
Copy link
Contributor

@torreytsui torreytsui commented Sep 17, 2018

Description

Caused by #13185, \Magento\Tax\Model\Sales\Total\Quote\Tax::clearValues() is called to unset the total before collecting total. null is expected (representing unset state) in below condition however 0 is set and failed the condition necessary to calculate correct shipping discount.

- expected
+ actual
// \Magento\SalesRule\Model\Validator::processShippingAmount
    public function processShippingAmount(Address $address)
    {
-        // $shippingAmount = null
+        // $shippingAmount = 0
        $shippingAmount = $address->getShippingAmountForDiscount();
        if ($shippingAmount !== null) {
            $baseShippingAmount = $address->getBaseShippingAmountForDiscount();
        } else {
            $shippingAmount = $address->getShippingAmount();
            $baseShippingAmount = $address->getBaseShippingAmount();
        }
        // ...
        $discountAmount = ($shippingAmount - $address->getShippingDiscountAmount()) * $rulePercent / 100;
        // ...
    }

Shipping discount fail to apply to an order, when:

  • order is checking out with payment method which do not collect total after savePaymentInformation() (for example, credit card methods usually meet this criteria, while paypal methods not)
  • order is applied with a promotional rule with shipping discount

Fixed Issues (if relevant)

Can't found any related issue so far

Manual testing scenarios

  1. Create coupon of 20%off discount and set it to applicable to shipping
  2. Apply the coupon
  3. Check out with Braintree
  4. After placed the order, go to account page to view the order

Expected result: Order discount contains shipping amount

Actual result: Order discount does not contain shipping amount

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-engcom-team
Copy link
Contributor

Hi @torreytsui

Unfortunately, we cannot accept Pull Requests from branches created in magento2 repository.
Please use your own fork as a base for this Pull Request.

Thank you.

@magento-engcom-team
Copy link
Contributor

Hi @torreytsui. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me $VERSION instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@torreytsui torreytsui deleted the feature/fix-shipping-discount-failed-to-apply branch September 17, 2018 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants